<template>
  <div>
    <el-tabs style="margin-top: 10px" tab-position="top">
      <!-- <el-tab-pane label="样品基本参数"> -->
      <el-card>
        <el-table :data="parameterList" height="500px" style="margin: 10px 0 10px" border
          :header-cell-style="{ background: '#FAFAFA' }">
          <el-table-column align="center" type="index"></el-table-column>
          <el-table-column align="center" label="牌号" prop="grade" width="120px"></el-table-column>
          <el-table-column align="center" label="样品规格" prop="specification" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="国别" prop="country"></el-table-column>
          <el-table-column align="center" label="生产商" prop="manufacturer" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="执行标准" prop="standard" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="标称密度/(kg/m³)" width="160px" prop="nominalDensity"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="单片厚度/mm" width="110px" prop="thickness"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="标称叠压系数" width="120px" prop="overlapCoefficient"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="饱和磁密/T" width="100px" prop="fluxDensity"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="饱和磁致伸缩系数/ppm" width="180px" prop="magCoefficient"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="电导率/(S/m)" width="110px" prop="electricalConductivity"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="热导率/(W/m-k)" width="130px" prop="heatConductivity"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="屈服强度/MPa" width="120px" prop="yieldStrength"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="居里温度/Cel.Deg" width="140px" prop="curieTemperature"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="入库日期" prop="inDate" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="样品柜编号" width="100px" prop="cabinetNumber"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="项目组" prop="projuctGroup" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="样品提供人" width="100px" prop="sampleProducer"
            show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="备注" prop="remarks" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="数据来源" width="200px" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click.native.stop="downloadAttachment(scope.row)">{{
                scope.row.dataSource }}</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="审核状态" fixed="right" width="150px">
            <template slot-scope="scope">
              <template v-if="scope.row.state == 1">
                <el-button style="color:green" type="text" size="mini">已通过</el-button>
                <el-divider direction="vertical"></el-divider>
                <el-button @click="openMeasurementConditions(scope.row);" style="color:gray" type="text"
                  size="mini">查看具体信息</el-button>
                <el-divider direction="vertical"></el-divider>
                <el-button @click="viewReview(scope.row)" type="text" size="mini">查看审核意见</el-button>
              </template>
              <template v-else-if="scope.row.state == -1">
                <el-button style="color:red" type="text" size="mini">未通过</el-button>
                <el-divider direction="vertical"></el-divider>
                <el-button @click="openMeasurementConditions(scope.row)" style="color:gray" type="text"
                  size="mini">查看具体信息</el-button>
                <el-divider direction="vertical"></el-divider>
                <el-button @click="viewReview(scope.row)" type="text" size="mini">查看审核意见</el-button>
              </template>
              <template v-else>
                <el-button style="color:skyblue" type="text" size="mini">审核中</el-button>
                <el-divider direction="vertical"></el-divider>
                <a-upload name="file" :action="uploadUrl" :data="{ id: scope.row.id, type: '软磁样品基本参数' }" :multiple="true"
                  @change="handleChange" :showUploadList="false">
                  <el-button type="text" size="mini">上传数据</el-button>
                </a-upload>
                <el-divider direction="vertical"></el-divider>
                <el-button @click="openMeasurementConditions(scope.row)" style="color:gray" type="text"
                  size="mini">查看具体信息</el-button>
              </template>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页区 -->
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum" :page-sizes="[10, 20]" :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
      </el-card>

      <!-- 查看审核意见 -->
      <el-dialog title="审核意见" :visible.sync="viewReviewVisible" width="30%">
        <span>{{ viewReviewContent }}</span>
      </el-dialog>
      <!-- 查看审核意见 -->

      <!-- 测量条件与测量列表 -->
      <el-dialog title="查询具体信息" :visible.sync="querySpecificInfoType" width="80%" :show-close="false"
        :close-on-click-modal="false">
        <measureSelectAndEchart ref="measureSelectAndEchart" :importDataType="'软磁性能'" :conditionNum="conditionNum"
          :tableRow="tableRow">
        </measureSelectAndEchart>
        <span slot="footer" class="dialog-footer">
          <el-button type="danger" size="small" style="margin-right: 20px" @click="closeQuery()">关闭</el-button>
        </span>
      </el-dialog>
      <!-- 测量条件与测量列表 -->
    </el-tabs>
  </div>
</template>

<script>
import { f_postAction } from '../../api/fileCheckApi'
import { f_httpAction } from '../../api/fileCheckApi'
import measureSelectAndEchart from './components/measureSelectAndEchart.vue'
import { Message } from 'element-ui'
export default {
  components: {
    measureSelectAndEchart
  },
  data() {
    return {
      tableRow: {},
      uploadUrl: 'http://59.172.104.174:30669/attachmentUpload/uploadAttachmentFile',
      /***********测量条件与测量列表*********** */
      conditionInfo: {
        curveTypes: '',
        timeTypes: '',
        productId: ''
      },
      conditionNum: {},
      querySpecificInfoType: false,
      /***********测量条件与测量列表*********** */

      viewReviewContent: '',
      viewReviewVisible: false,

      parameterList: [],

      //基本参数分页
      queryInfo: {
        //当前的页数
        pageNum: 1,
        //当前每页显示多少条数据
        pageSize: 10,
        type: '软磁样品基本参数',
        productId: ''
      },
      total: 0
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    /*******************上传数据******************* */
    handleChange(info) {
      if (info.file.status === 'done') {
        if (info.file.response.code == '201') {
          Message({
            message: '重新上传成功！',
            type: 'success',
            center: true,
            customClass: 'mzindex'
          })
        } else if (info.file.response.code == 200) {
          Message({
            message: '上传成功！',
            type: 'success',
            center: true,
            customClass: 'mzindex'
          })
          this.loadData()
        }
      }
    },
    downloadAttachment(row) {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: '/attachmentUpload/downLoadAttachmentFile',
        method: 'GET',
        params: {
          filename: row.dataSource
        },
        responseType: 'blob' // 表明返回服务器返回的数据类型
      }).then(res => {
        let blob = new Blob([res.data])
        let fileName = row.dataSource
        if (window.navigator.msSaveOrOpenBlob) {
          navigator.msSaveBlob(blob, fileName)
        } else {
          var link = document.createElement('a')
          link.href = window.URL.createObjectURL(blob)
          link.download = fileName
          link.click()
          //释放内存
          window.URL.revokeObjectURL(link.href)
        }
      })
    },
    /*******************上传数据******************* */

    /*******************查看审核意见******************* */
    viewReview(row) {
      this.viewReviewContent = row.message
      this.viewReviewVisible = true
    },
    /*******************查看审核意见******************* */

    //页码改变
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
      this.loadData()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
      this.loadData()
    },
    //获取基本参数
    loadData() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: '/checkTable/selectParameterByUserId',
        method: 'GET',
        params: {
          userId: JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.id,
          type: '软磁样品基本参数',
          pageNum: this.queryInfo.pageNum,
          pageSize: this.queryInfo.pageSize
        }
      }).then(res => {
        this.parameterList = res.data.result.list.records
        this.total = res.data.result.list.total
      })
    },
    closeQuery() {
      this.querySpecificInfoType = false
    },
    openMeasurementConditions(row) {
      this.tableRow = row.specification
      console.log("this.tableRow", this.tableRow)
      this.querySpecificInfoType = true
      this.axios({
        //获取数量
        baseURL: 'http://59.172.104.174:30669',
        url: `/productParameter/selectNum?id=${row.id}`,
        methods: 'GET'
      }).then(res => {
        this.conditionNum = res.data.result
        this.conditionInfo.productId = row.id
        console.log("ssssss1", row.specification)
        this.$refs.measureSelectAndEchart.getDataFromUp(this.conditionInfo, row.specification)
      })
    }
  }
}
</script>

<style scoped></style>
